package com.yyg.boot.mq;

import com.yyg.boot.domain.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author 一一哥Sun
 * @Date Created in 2020/4/16
 * @Description Description
 */
@Slf4j
@Component
public class RabbitProducer {

    @Autowired
    private AmqpTemplate template;

    public void sendMsg() {
        //Message msg=new Message();
        //template.send(msg);

        //第一个参数是路由键
        String content="hello,"+new Date();
        log.warn("消息发送--->content={}",content);
        template.convertAndSend("firstRabbit", content);
    }

    //发送对象
    public void sendUser() {
        User user=new User();
        user.setId(1L);
        user.setUsername("syc");
        user.setPassword("123");
        log.warn("消息发送--->User={}",user.toString());
        template.convertAndSend("firstObject", user);
    }

}
